var Tool = require('../tool/ztool.js');
var tool = new Tool();
Page({
  data: {
    list: [],
    titles: ['需求标题', '公司', '联系人', '手机号', '车型', '所需车位', '乘车人数', '性质', '是否公开']
  },
  onLoad: function (options) {
    // 生命周期函数--监听页面加载
    console.log('onLoad', options);
    var idd = options.idd;
    var that = this;
    if (!that.data.idd) {
      this.setData({
        idd: idd
      });
    }
    getDetail(this);
  },

  onShareAppMessage: function () {
    // 用户点击右上角分享
    return {
      title: 'title', // 分享标题
      desc: 'desc', // 分享描述
      path: 'path' // 分享路径
    }
  }
})

function getDetail(that) {
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CoverCarInfo.ashx',
    data: {
      ID: that.data.idd,
    },
    method: 'GET',
    success: function (res) {
      wx.hideToast();
      var newRes = tool.getRegularJson(res.data);
      console.log('套车详情', newRes, 'idd',that.data.idd);
      var oderInfo = newRes.data[0];
      var inforArr = dealData(oderInfo);
      that.setData({
        list: oderInfo,
        inforArr: inforArr,
        loadError: false
      });
    },

    fail: function () {
      wx.hideToast();
      that.setData({
        loadError: true
      });
    }
  });

}

//对数据进行处理，
function dealData(oderInfo) {
  console.log('处理数据', oderInfo);
  var isPublic;
  if (oderInfo.mIsPublic == '1') {
    isPublic = '公开';
  } else {
    isPublic = '未公开';
  }
  var inforArr = [oderInfo.mTitle, oderInfo.mCompanyName, oderInfo.mConnector, oderInfo.mConnectTel, oderInfo.mCarType, oderInfo.mSeatNum, oderInfo.mPersonCnt, oderInfo.mType, isPublic];
  for (var i = 0; i < inforArr.length; i++) {
    if (inforArr[i].length == 0) {
      if (i == 5 || i == 6) {
        inforArr.splice(i, 1, "0");
        continue;
      }
      if (i == inforArr.length - 1) {
        continue;
      }
      inforArr.splice(i, 1, "未填写");
    }
  }
  return inforArr;
}
